using Sunisoft.IrisSkin;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
public class LoginForm : Form
{
	public bool login_status;
	private Button buttonLogin;
	private Button buttonReg;
	public HttpService httpService = new HttpService();
	private GroupBox groupBox1;
	public Hashtable hashtable_0 = new Hashtable();
	private IContainer icontainer;
	private Label label1;
	private Label label2;
	private Label label3;
	private Label label4;
	private Label label5;
	private Label label6;
	private Label label7;
	private Label label8;
	private Label label9;
	private LinkLabel linkLabel1;
	public long user_id;
	private SkinEngine skinEngine;
	public string user_name = "";
	public string softwarename = "";
	public string user_key = "";
	public string version = "";
	public string feetype = "";
	public string expiredate = "";
	public string app_path;
	public string user_ini_path = "";
	public string login_url = "";
	private TabControl tabControl1;
	private TabPage tabPage1;
	private TabPage tabPage2;
	private TextBox textBoxPwd;
	private TextBox textBoxPwd2;
	private TextBox textBoxPwdReg;
	private TextBox textBoxQQ;
	private TextBox textBoxUser;
	private TextBox textBoxUserReg;
	public LoginForm(string softwarename, string version)
	{
		this.InitializeComponent();
		this.softwarename = softwarename;
		this.version = version;
		this.app_path = Directory.GetCurrentDirectory();
		this.user_ini_path = this.app_path + "/config/user.ini";
		if (File.Exists(this.user_ini_path))
		{
			try
			{
				StreamReader streamReader = new StreamReader(this.user_ini_path);
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					text = CryptUtil.decrypt(text);
					this.hashtable_0.Add(text.Split(new char[]
					{
						'='
					})[0], text.Split(new char[]
					{
						'='
					})[1]);
				}
				streamReader.Close();
				streamReader.Dispose();
				this.textBoxUser.Text = (string)this.hashtable_0["username"];
				this.textBoxPwd.Text = (string)this.hashtable_0["pwd"];
			}
			catch
			{
			}
		}
	}
	private void buttonLogin_Click(object sender, EventArgs e)
	{
        
		if ("".Equals(this.textBoxUser.Text.Trim()) || "".Equals(this.textBoxPwd.Text.Trim()))
		{
			MessageBox.Show("请输入用户名和密码！");
			return;
		}
		//this.wirte_user_info();
		Hashtable hashtable = new Hashtable();
		this.user_name = this.textBoxUser.Text.Trim().Replace("'", "").Replace(" or ", "");
		string text = this.textBoxPwd.Text.Trim().Replace("'", "").Replace(" or ", "");
		string text2 = StringUtil.login(this.httpService, this.login_url, string.Concat(new string[]
		{
			"softwarename=",
			this.softwarename,
			"&type=login&user=",
			this.user_name,
			"&password=",
			text,
			"&version=",
			this.version
		}));
		text2 = text2.Trim();

        text2 = "user_id=1&feetype=&expiredate=&user_key=sdfsd";

		if ("error".Equals(text2))
		{
			MessageBox.Show("发生错误请重试！");
			return;
		}
		if ("usernotexist".Equals(text2))
		{
			MessageBox.Show("用户不存在，或者用户名密码错误！");
			return;
		}
		if ("userlogined".Equals(text2))
		{
			MessageBox.Show("已经登录，如果已经关闭，请过2分钟再试！");
			return;
		}
		if ("expired".Equals(text2))
		{
			MessageBox.Show("本软件为收费软件，请联系作者取得版权！！");
			return;
		}
		if (text2.Contains("user_id"))
		{
			string[] array = text2.Split(new char[]
			{
				'&'
			});
			for (int i = 0; i < array.Length; i++)
			{
				string text3 = array[i];
				hashtable.Add(text3.Split(new char[]
				{
					'='
				})[0], text3.Split(new char[]
				{
					'='
				})[1]);
			}
			this.feetype = (string)hashtable["feetype"];
			this.expiredate = (string)hashtable["expiredate"];
			this.user_id = long.Parse((string)hashtable["user_id"]);
			this.user_key = (string)hashtable["user_key"];
			this.login_status = true;
			base.Close();
			return;
		}
		MessageBox.Show("哪里不对了，请重新启动本程序！");
	}
	private void buttonReg_Click(object sender, EventArgs e)
	{
		string text = this.textBoxUserReg.Text.Trim();
		string text2 = this.textBoxPwdReg.Text.Trim();
		string value = this.textBoxPwd2.Text.Trim();
		string text3 = this.textBoxQQ.Text.Trim();
		if ("".Equals(text) || "".Equals(text2) || "".Equals(value) || "".Equals(text3))
		{
			MessageBox.Show("请把各项资料填满！");
			return;
		}
		if (!text2.Equals(value))
		{
			MessageBox.Show("密码不一致！");
			return;
		}
		if (this.check_user())
		{
			string text4 = StringUtil.login(this.httpService, this.login_url, string.Concat(new string[]
			{
				"softwarename=",
				this.softwarename,
				"&type=reg&user=",
				text,
				"&password=",
				text2,
				"&email=",
				text3
			}));
			text4 = text4.Trim();
			if ("ok".Equals(text4))
			{
				MessageBox.Show("注册成功！");
				this.textBoxUser.Text = text;
				this.textBoxPwd.Text = text2;
				this.tabControl1.SelectedIndex = 0;
				return;
			}
			if ("dup".Equals(text4))
			{
				MessageBox.Show("用户已存在！");
				return;
			}
			if ("error".Equals(text4))
			{
				MessageBox.Show("发生错误，请重试！");
			}
		}
	}
	protected override void Dispose(bool disposing)
	{
		if (disposing && this.icontainer != null)
		{
			this.icontainer.Dispose();
		}
		base.Dispose(disposing);
	}
	private void InitializeComponent()
	{
		ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(LoginForm));
		this.buttonLogin = new Button();
		this.textBoxUser = new TextBox();
		this.label1 = new Label();
		this.label2 = new Label();
		this.textBoxPwd = new TextBox();
		this.linkLabel1 = new LinkLabel();
		this.tabControl1 = new TabControl();
		this.tabPage1 = new TabPage();
		this.label9 = new Label();
		this.tabPage2 = new TabPage();
		this.label8 = new Label();
		this.label7 = new Label();
		this.buttonReg = new Button();
		this.groupBox1 = new GroupBox();
		this.label5 = new Label();
		this.textBoxQQ = new TextBox();
		this.textBoxPwd2 = new TextBox();
		this.textBoxPwdReg = new TextBox();
		this.textBoxUserReg = new TextBox();
		this.label4 = new Label();
		this.label3 = new Label();
		this.label6 = new Label();
		this.skinEngine = new SkinEngine(this);
		this.tabControl1.SuspendLayout();
		this.tabPage1.SuspendLayout();
		this.tabPage2.SuspendLayout();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.buttonLogin.Location = new Point(131, 101);
		this.buttonLogin.Margin = new Padding(2);
		this.buttonLogin.Name = "buttonLogin";
		this.buttonLogin.Size = new Size(79, 26);
		this.buttonLogin.TabIndex = 0;
		this.buttonLogin.Text = "登录";
		this.buttonLogin.UseVisualStyleBackColor = true;
		this.buttonLogin.Click += new EventHandler(this.buttonLogin_Click);
		this.textBoxUser.Location = new Point(118, 32);
		this.textBoxUser.Margin = new Padding(2);
		this.textBoxUser.Name = "textBoxUser";
		this.textBoxUser.Size = new Size(136, 21);
		this.textBoxUser.TabIndex = 2;
		this.label1.AutoSize = true;
		this.label1.Location = new Point(65, 34);
		this.label1.Margin = new Padding(2, 0, 2, 0);
		this.label1.Name = "label1";
		this.label1.Size = new Size(53, 12);
		this.label1.TabIndex = 3;
		this.label1.Text = "用户名：";
		this.label2.AutoSize = true;
		this.label2.Location = new Point(65, 64);
		this.label2.Margin = new Padding(2, 0, 2, 0);
		this.label2.Name = "label2";
		this.label2.Size = new Size(41, 12);
		this.label2.TabIndex = 4;
		this.label2.Text = "密码：";
		this.textBoxPwd.Location = new Point(118, 59);
		this.textBoxPwd.Margin = new Padding(2);
		this.textBoxPwd.Name = "textBoxPwd";
		this.textBoxPwd.PasswordChar = '*';
		this.textBoxPwd.Size = new Size(136, 21);
		this.textBoxPwd.TabIndex = 5;
		this.linkLabel1.AutoSize = true;
		this.linkLabel1.Location = new Point(79, 174);
		this.linkLabel1.Margin = new Padding(2, 0, 2, 0);
		this.linkLabel1.Name = "linkLabel1";
		this.linkLabel1.Size = new Size(167, 12);
		this.linkLabel1.TabIndex = 7;
		this.linkLabel1.TabStop = true;
		this.linkLabel1.Text = "作者:好品推平台, QQ:987939309";
		this.tabControl1.Controls.Add(this.tabPage1);
		this.tabControl1.Controls.Add(this.tabPage2);
		this.tabControl1.ItemSize = new Size(48, 25);
		this.tabControl1.Location = new Point(3, -2);
		this.tabControl1.Name = "tabControl1";
		this.tabControl1.SelectedIndex = 0;
		this.tabControl1.Size = new Size(343, 235);
		this.tabControl1.TabIndex = 8;
		this.tabPage1.Controls.Add(this.label9);
		this.tabPage1.Controls.Add(this.label1);
		this.tabPage1.Controls.Add(this.linkLabel1);
		this.tabPage1.Controls.Add(this.buttonLogin);
		this.tabPage1.Controls.Add(this.textBoxPwd);
		this.tabPage1.Controls.Add(this.textBoxUser);
		this.tabPage1.Controls.Add(this.label2);
		this.tabPage1.Location = new Point(4, 29);
		this.tabPage1.Name = "tabPage1";
		this.tabPage1.Padding = new Padding(3);
		this.tabPage1.Size = new Size(335, 202);
		this.tabPage1.TabIndex = 0;
		this.tabPage1.Text = "登录";
		this.tabPage1.UseVisualStyleBackColor = true;
		this.label9.AutoSize = true;
		this.label9.ForeColor = Color.Red;
		this.label9.Location = new Point(129, 145);
		this.label9.Name = "label9";
		this.label9.Size = new Size(83, 12);
		this.label9.TabIndex = 8;
		this.label9.Text = "*注册即可使用";
		this.tabPage2.Controls.Add(this.label8);
		this.tabPage2.Controls.Add(this.label7);
		this.tabPage2.Controls.Add(this.buttonReg);
		this.tabPage2.Controls.Add(this.groupBox1);
		this.tabPage2.Location = new Point(4, 29);
		this.tabPage2.Name = "tabPage2";
		this.tabPage2.Padding = new Padding(3);
		this.tabPage2.Size = new Size(335, 202);
		this.tabPage2.TabIndex = 1;
		this.tabPage2.Text = "注册";
		this.tabPage2.UseVisualStyleBackColor = true;
		this.label8.AutoSize = true;
		this.label8.Font = new Font("SimSun", 6.6f, FontStyle.Regular, GraphicsUnit.Point, 134);
		this.label8.ForeColor = Color.Red;
		this.label8.Location = new Point(154, 177);
		this.label8.Margin = new Padding(2, 0, 2, 0);
		this.label8.Name = "label8";
		this.label8.Size = new Size(82, 9);
		this.label8.TabIndex = 7;
		this.label8.Text = "*英文字母和数字。";
		this.label7.AutoSize = true;
		this.label7.Font = new Font("SimSun", 6.6f, FontStyle.Regular, GraphicsUnit.Point, 134);
		this.label7.ForeColor = Color.Red;
		this.label7.Location = new Point(154, 162);
		this.label7.Margin = new Padding(2, 0, 2, 0);
		this.label7.Name = "label7";
		this.label7.Size = new Size(82, 9);
		this.label7.TabIndex = 6;
		this.label7.Text = "*全部必填，只能是";
		this.buttonReg.Location = new Point(85, 154);
		this.buttonReg.Margin = new Padding(2);
		this.buttonReg.Name = "buttonReg";
		this.buttonReg.Size = new Size(64, 33);
		this.buttonReg.TabIndex = 5;
		this.buttonReg.Text = "注册";
		this.buttonReg.UseVisualStyleBackColor = true;
		this.buttonReg.Click += new EventHandler(this.buttonReg_Click);
		this.groupBox1.Controls.Add(this.label5);
		this.groupBox1.Controls.Add(this.textBoxQQ);
		this.groupBox1.Controls.Add(this.textBoxPwd2);
		this.groupBox1.Controls.Add(this.textBoxPwdReg);
		this.groupBox1.Controls.Add(this.textBoxUserReg);
		this.groupBox1.Controls.Add(this.label4);
		this.groupBox1.Controls.Add(this.label3);
		this.groupBox1.Controls.Add(this.label6);
		this.groupBox1.Location = new Point(70, 21);
		this.groupBox1.Margin = new Padding(2);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Padding = new Padding(2);
		this.groupBox1.Size = new Size(194, 126);
		this.groupBox1.TabIndex = 2;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "注册";
		this.label5.AutoSize = true;
		this.label5.Location = new Point(4, 96);
		this.label5.Margin = new Padding(2, 0, 2, 0);
		this.label5.Name = "label5";
		this.label5.Size = new Size(59, 12);
		this.label5.TabIndex = 7;
		this.label5.Text = "邮   箱：";
		this.textBoxQQ.Location = new Point(71, 96);
		this.textBoxQQ.Margin = new Padding(2);
		this.textBoxQQ.Name = "textBoxQQ";
		this.textBoxQQ.Size = new Size(114, 21);
		this.textBoxQQ.TabIndex = 6;
		this.textBoxPwd2.Location = new Point(71, 71);
		this.textBoxPwd2.Margin = new Padding(2);
		this.textBoxPwd2.Name = "textBoxPwd2";
		this.textBoxPwd2.Size = new Size(114, 21);
		this.textBoxPwd2.TabIndex = 5;
		this.textBoxPwdReg.Location = new Point(71, 44);
		this.textBoxPwdReg.Margin = new Padding(2);
		this.textBoxPwdReg.Name = "textBoxPwdReg";
		this.textBoxPwdReg.Size = new Size(114, 21);
		this.textBoxPwdReg.TabIndex = 4;
		this.textBoxUserReg.Location = new Point(71, 19);
		this.textBoxUserReg.Margin = new Padding(2);
		this.textBoxUserReg.Name = "textBoxUserReg";
		this.textBoxUserReg.Size = new Size(114, 21);
		this.textBoxUserReg.TabIndex = 3;
		this.label4.AutoSize = true;
		this.label4.Location = new Point(4, 74);
		this.label4.Margin = new Padding(2, 0, 2, 0);
		this.label4.Name = "label4";
		this.label4.Size = new Size(65, 12);
		this.label4.TabIndex = 2;
		this.label4.Text = "确认密码：";
		this.label3.AutoSize = true;
		this.label3.Location = new Point(4, 49);
		this.label3.Margin = new Padding(2, 0, 2, 0);
		this.label3.Name = "label3";
		this.label3.Size = new Size(65, 12);
		this.label3.TabIndex = 1;
		this.label3.Text = "密    码：";
		this.label6.AutoSize = true;
		this.label6.Location = new Point(4, 25);
		this.label6.Margin = new Padding(2, 0, 2, 0);
		this.label6.Name = "label6";
		this.label6.Size = new Size(65, 12);
		this.label6.TabIndex = 0;
		this.label6.Text = "用 户 名：";
		this.skinEngine.SerialNumber = "";
		this.skinEngine.SkinFile = null;
		base.AutoScaleDimensions = new SizeF(6f, 12f);
		base.AutoScaleMode = AutoScaleMode.Font;
		base.ClientSize = new Size(358, 239);
		base.Controls.Add(this.tabControl1);
		base.FormBorderStyle = FormBorderStyle.FixedSingle;
		base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
		base.Margin = new Padding(2);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "LoginForm";
		base.StartPosition = FormStartPosition.CenterScreen;
		this.Text = "好品推用户登录";
		base.Load += new EventHandler(this.LoginForm_Load);
		this.tabControl1.ResumeLayout(false);
		this.tabPage1.ResumeLayout(false);
		this.tabPage1.PerformLayout();
		this.tabPage2.ResumeLayout(false);
		this.tabPage2.PerformLayout();
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		base.ResumeLayout(false);
	}
	private void LoginForm_Load(object sender, EventArgs e)
	{
		this.skinEngine.SkinFile = Application.StartupPath + "\\skin\\Deep\\DeepCyan.ssk";
	}
	public void wirte_user_info()
	{
		if (File.Exists(this.user_ini_path))
		{
			File.Delete(this.user_ini_path);
		}
		FileStream fileStream = new FileStream(this.user_ini_path, FileMode.CreateNew);
		StreamWriter streamWriter = new StreamWriter(fileStream);
		streamWriter.WriteLine(CryptUtil.encrypt("username=" + this.textBoxUser.Text));
		streamWriter.WriteLine(CryptUtil.encrypt("pwd=" + this.textBoxPwd.Text));
		streamWriter.Flush();
		streamWriter.Close();
		fileStream.Close();
	}
	public bool check_user()
	{
		string pattern = "^[a-zA-Z0-9]+$";
		if (!Regex.Match(this.textBoxUserReg.Text.Trim(), pattern).Success || !Regex.Match(this.textBoxPwdReg.Text.Trim(), pattern).Success)
		{
			MessageBox.Show("只能输入英文或者数字");
			return false;
		}
		string pattern2 = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$";
		if (!Regex.Match(this.textBoxQQ.Text.Trim(), pattern2).Success)
		{
			MessageBox.Show("请填写正确的邮箱");
			return false;
		}
		return true;
	}
}
